<?php
include('simple_html_dom.php');

if(!isset($_GET["imdb"])){
	exit("unable to open file ");
}
$imdbId = $_GET["imdb"];

$cxContext=null;
if(isset($_GET["p"]) && $_GET["p"] == 1){
	$aContext  = array(
    'http' => array(
        'proxy' => 'web-proxy.isr.hp.com:8080',
        'request_fulluri' => true
    )
	);
	$cxContext = stream_context_create($aContext);
}
$string="http://www.imdb.com/title/".$imdbId."/episodes/_ajax?year=".date('Y');
$html = @file_get_html($string,  false, $cxContext);
if($html === FALSE) { 
	exit("unable to open filez ");
}
$series = array();
foreach($html->find('div.list_item') as $element){
	$show = array();
    $date = $element->find('.airdate', 0)->plaintext;
	$show['airdate']=strtotime($date);
	$seasonEpisode = $element->find('.hover-over-image div', 0)->plaintext;
	preg_match_all('/\d+/', $seasonEpisode, $matches);
	$show['season'] = $matches;
	$show['season'] = null;
	$show['episode'] = null;
	if(count($matches[0])>0){
		$show['season'] = $matches[0][0];
		$show['episode'] = $matches[0][1];
	}
	array_push($series, $show);
}
header('Content-Type: application/json');
echo json_encode($series);
?>